<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html style="height:100%" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <meta http-equiv="Content-Style-Type" content="text/css" />
    <meta name="keywords" content="javascript framework, RIA, SPA, client SOA, linb, jsLinb, RAD, IDE, Web IDE, widgets, javascript OOP, opensource, open-source, Ajax, cross-browser, prototype, web2.0, platform-independent, language-independent" />
    <meta name="description" content="Web application created by Visual JS, powered by LINB framework" />
    <meta name="copyright" content="copyright@www.linb.net" />
    <meta http-equiv="imagetoolbar" content="no" />
    <title>Web application powered by LINB framework</title>
</head>
    <body style="height:100%;overflow:hidden;" scroll="no">
        <div id='loading'><img src="../jsontest/runtime/loading.gif" alt="Loading..." /></div>
        <script type="text/javascript" src="../jsontest/runtime/jsLinb/js/linb-all.js"></script>
        <script type="text/javascript">

Class('App', 'linb.Com',{
    Instance:{
        //base Class for this com
        base:["linb.UI"], 
        //requried class for this com
        required:["linb.DataBinder", "linb.UI.TreeGrid", "linb.UI.Button", "linb.UI.Input"], 

        properties:{}, 
        events:{"onReady":"_onready","onRender":"_onrender"}, 
        iniResource:function(com, threadid){
        }, 
        iniComponents:function(){
            // [[code created by jsLinb UI Builder
            var host=this, children=[], append=function(child){children.push(child.get(0))};
            

            
            append((new linb.DataBinder)
                .host(host,"databinder3")
                .setName("dataset")
            );
            
            append((new linb.UI.TreeGrid)
                .host(host,"testgrid")
                .setDock("middle")
                .setLeft(80)
                .setTop(100)
                .setWidth(320)
                .setHeight(370)
                .setAltRowsBg(true)
                .setHeader([
                {"id":"id","width":10,"type":"label","caption":"id"},
                {"id":"ip", "width":80, "type":"label", "caption":"设备IP"},
                {"id":"descri", "width":80, "type":"label", "caption":"设备型号"},
                {"id":"product_desc", "width":80, "type":"label", "caption":"描述"},
                {"id":"location", "width":80, "type":"label", "caption":"放置地点"}])
                .afterRowActive("_testgrid_afterrowactive")
            );

            append((new linb.UI.Button)
                .host(host,"button8")
                .setLeft(460)
                .setTop(520)
                .setCaption("获取数据")
                .onClick("_button8_onclick")
            );
            
            append((new linb.UI.Input)
                .host(host,"descri")
                .setDataBinder("dataset")
                .setDataField("descri")
                .setLeft(510)
                .setTop(210)
                .setWidth(210)
            );
            
            append((new linb.UI.Input)
                .host(host,"product_desc")
                .setDataBinder("dataset")
                .setDataField("product_desc")
                .setLeft(510)
                .setTop(270)
                .setWidth(210)
            );
            
            append((new linb.UI.Button)
                .host(host,"button11")
                .setLeft(590)
                .setTop(310)
                .setCaption("更新")
                .onClick("_button11_onclick")
            );
            
            append((new linb.UI.Input)
                .host(host,"ip")
                .setDataBinder("dataset")
                .setDataField("ip")
                .setLeft(510)
                .setTop(150)
                .setWidth(210)
                .setReadonly(true)
            );
            
            append((new linb.UI.Input)
                .host(host,"id")
                .setDataBinder("dataset")
                .setDataField("id")
                .setLeft(0)
                .setTop(0)
                .setVisibility("hidden")
            );            
            return children;
            // ]]code created by jsLinb UI Builder
        }, 
        iniExComs:function(com, hreadid){
        }, 
        _button8_onclick:function (profile, e, src, value) {
            var me = this;
            linb.request(
            "http://localhost:8080/jsontest/jspjson.jsp",
            null,
            function(rep, type){
                var obj = _.unserialize(rep);
				
				if (obj.code == 0) {
                	me.testgrid.setRows(_.unserialize(obj.datas));
                }
            });
        }, 
        _onready:function (com, threadid) {
            me =this;
        }, 
        _onrender:function (com, threadid) {
            me.testgrid.showColumn('id',false);
            me.id.resetValue('0');
        },
        _testgrid_afterrowactive:function (profile, row) {
        	me.$row = row;

        	me.id.resetValue(row.cells[0].value);
            me.ip.resetValue(row.cells[1].value);
            me.descri.resetValue(row.cells[2].value);
            me.product_desc.resetValue(row.cells[3].value);
        }, 
        _button11_onclick:function (profile, e, src, value) {
        	if (!me.$row) {alert('oooo');return};
            var newobj = _.serialize(me.databinder3.getValue());
            alert(newobj);
            linb.request(
            "http://localhost:8080/jsontest/upjson.jsp",
            "action=up&dv="+newobj,
            function(rep){
                var obj = _.unserialize(rep);
				if (obj.code == 0) {
					alert(obj.messages);
					cells = me.$row.cells;
					me.testgrid.updateCell(cells[2],me.descri.getValue(),false);
					me.testgrid.updateCell(cells[3],me.product_desc.getValue(),false);					
					me.$row = null;
                } else {
                	alert(obj.messages);
                }
                
            });            
        }
    }
});

//linb.setAppLangKey('app');
linb.UI.setTheme('default');
linb.Com.load('App', function(){linb('loading').remove()}, 'cn');

        </script>
</body>
</html>